package com.muyu.system.controller;


import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.poi.ExcelUtil;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.core.web.page.TableDataInfo;
import com.muyu.common.log.annotation.Log;
import com.muyu.common.log.enums.BusinessType;
import com.muyu.common.security.annotation.RequiresPermissions;
import com.muyu.common.security.utils.SecurityUtils;
import com.muyu.common.system.domain.LoginUser;
import com.muyu.system.domain.DanmoUserFlagship;
import com.muyu.system.service.IDanmoUserFlagshipService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 旗舰店关注Controller
 *
 * @author kunzong
 * @date 2024-12-24
 */
@RestController
@RequestMapping("/DanmoUserFlagship")
public class DanmoUserFlagshipController extends BaseController {
    @Autowired
    private IDanmoUserFlagshipService danmoUserFlagshipService;

    /**
     * 查询旗舰店关注列表
     */
//    @RequiresPermissions("system:DanmoUserFlagship:list")
    @GetMapping("/list")
    public Result list(DanmoUserFlagship danmoUserFlagship) {
        startPage();
        List<DanmoUserFlagship> list = danmoUserFlagshipService.selectDanmoUserFlagshipList(danmoUserFlagship);
        return Result.success(list);
    }

    /**
     * 导出旗舰店关注列表
     */
//    @RequiresPermissions("system:DanmoUserFlagship:export")
    @Log(title = "旗舰店关注", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DanmoUserFlagship danmoUserFlagship) {
        List<DanmoUserFlagship> list = danmoUserFlagshipService.selectDanmoUserFlagshipList(danmoUserFlagship);
        ExcelUtil<DanmoUserFlagship> util = new ExcelUtil<DanmoUserFlagship>(DanmoUserFlagship.class);
        util.exportExcel(response, list, "旗舰店关注数据");
    }

    /**
     * 获取旗舰店关注详细信息
     */
//    @RequiresPermissions("system:DanmoUserFlagship:query")
    @GetMapping(value = "/{id}")
    public Result getInfo(@PathVariable("id") Long id) {
        return Result.success(danmoUserFlagshipService.selectDanmoUserFlagshipById(id));
    }

    /**
     * 新增旗舰店关注
     */
//    @RequiresPermissions("system:DanmoUserFlagship:add")
    @Log(title = "旗舰店关注", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody DanmoUserFlagship danmoUserFlagship) {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        if (loginUser == null) {
            return Result.notLoggedIn("请登录");
        }
        danmoUserFlagship.setUserId(loginUser.getUserid());
        return danmoUserFlagshipService.insertDanmoUserFlagship(danmoUserFlagship);
    }

    /**
     * 修改旗舰店关注
     */
//    @RequiresPermissions("system:DanmoUserFlagship:edit")
    @Log(title = "旗舰店关注", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody DanmoUserFlagship danmoUserFlagship) {
        return Result.success(danmoUserFlagshipService.updateDanmoUserFlagship(danmoUserFlagship));
    }

    /**
     * 取消旗舰店关注
     */
//    @RequiresPermissions("system:DanmoUserFlagship:remove")
    @Log(title = "旗舰店关注", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public Result remove(@PathVariable Long[] ids) {
        return Result.success(danmoUserFlagshipService.deleteDanmoUserFlagshipByIds(ids), "取消关注成功");
    }
}
